package com.example.common.exception;

import com.example.common.enums.GlobalExceptionEnum;
import lombok.Data;

/**
 * 通用异常类
 *
 * @author 12071
 * @date 2022/8/9 22:38
 */
@Data
public class UniversalException extends RuntimeException{
    private String code;

    private String message;

    private UniversalException(GlobalExceptionEnum enums) {
        this.code = enums.getCode();
        this.message = enums.getMessage();
    }

    private UniversalException(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static UniversalException build(GlobalExceptionEnum enums) {
        return new UniversalException(enums);
    }

    public static UniversalException build(String code, String message) {
        return new UniversalException(code, message);
    }
}
